/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.dswII.bl;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.itsc.dswII.dao.InteresDaoLocal;
import mx.itsc.dswII.ennumeracionl.EstadoTransaccion;
import mx.itsc.dswII.model.Interes;

/**
 *
 * @author Lenovo-user
 */
@Stateless
public class InteresBl implements InteresBlLocal {
    @EJB
    private InteresDaoLocal interesDao;
@Override
    public EstadoTransaccion register(Interes interes) {
         if (interesDao.findDuplicity(interes)) {
            //no se pudo hacer
            return EstadoTransaccion.INCOMPLETO;
        } else {
            interesDao.create(interes);
            // ya lo hizo
            return EstadoTransaccion.COMPLETO;

        }
    }
 @Override
    public EstadoTransaccion modify(Interes interes) {
        if (interes.getId() == null || interesDao.find(interes.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            interesDao.edit(interes);
            return EstadoTransaccion.COMPLETO;
        }

    }

    @Override
    public EstadoTransaccion remove(Interes interes) {

        if (interesDao.find(interes.getId()) == null || interes.getId() == null) {

            return EstadoTransaccion.INCOMPLETO;
        } else {
            interesDao.remove(interes);
            return EstadoTransaccion.COMPLETO;
        }

    }
    
    @Override
    public List<Interes> getAll() {
        return interesDao.findAll();
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

 public List<Interes> getListByCategoria(Interes interes) {
        List<Interes> interesList = interesDao.findByInteres(interes);
        List<Interes> finalinteresList = new ArrayList<Interes>();
        
        for (Interes emp : interesList) {
            finalinteresList.add(emp);
        }
        return finalinteresList;
    }
}
